<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>账号注册</title>
    <meta name="keywords" content="注册_机械猫">
    {load file='__pc_static__/css/init.css'}
    {load file='__pc_static__/css/login.css'}
</head>
<body>
    <div id="register">
        <div class="box">
            <div class="top"><img src=""></div>
            <form action="{:url('User/register',['step'=>4])}" method="post" onsubmit="javascript:return register();">
                <dl>
                    <dt><h1>注册机械猫账号</h1></dt>
                    <dd class="text no-border">我们已经发送一条验证短信至 <span class="in-orange">+86 {$mobile}</span></dd>
                    <dd class="text no-border">请输入短信中的验证码</dd>
                    <dd class="code coding no-border"><input  type="text" name="code" value=""><span class="post_send img_code current code_box" onclick="javascript:post_send(true);">重新发送</span></dd>
                    <dd class="btn no-border"><input type="submit" value="注册"></dd>
                    <dd class="btn no-border"><input type="button" value="返回上一步" onclick="javascript:location.href='{:url('User/register',['step'=>1])}'"></dd>
                </dl>
            </form>
        </div>
    </div>
</body>
</html>
{load file='__static__/js/jquery.min.js'}
{load file='__static__/js/think_filter.js'}
{load file='__pc_static__/js/think_Userinfo.js'}
{load file='__pc_static__/js/jack-input-default.js'}

<script>
    $(function(){
        _login.attr_set([['phone','请输入手机号码'],['code','请输入验证码']]);
        $('#register input[type=text]').each(function(){
            _login.default_set($(this));
        });
        $('#register input[type=text]').on('blur click dblclick',function(){
            _login.default_set($(this));
        });

        //倒计时
        var interval = null;
        var interval_num = 3;

        window.post_send  = function(is_post)
        {
//            if(interval_num != 60) return;
            var _target = $('#register .post_send');
            interval = window.setInterval(function(){
                if(interval_num<=0)
                {
                    interval_num = 3;
                    window.clearInterval(interval);
                }
                _target.html('重新发送('+interval_num+')');
                interval_num--;
            },1000);

            //重新发送验证码
            if(is_post == true)
            {
                var url = '{:url("User/register",["step"=>3])}';
                var data = {phone:'{$mobile}'};
                $.post(url,data,function(data){
                    if(typeof data.msg != 'undefined')
                        alert(data.msg);
                    else
                        alert('服务器错误');
                },'json')
            }

        }

        //倒数
        post_send(false);
        alert('请不要刷新页面');

        //注册
        window.register = function()
        {
            var url = "{:url('User/register',['step'=>4])}";
            var data = {
                code : $('input[name=code]').val()
            };
            if(data.code == "")
            {
                alert('请输入验证码');
                return;
            }

            $.post(url,data,function(data){
                if(typeof data.msg != "undefined")
                {
                    alert(data.msg);
                    //注册成功
                    if(data.error == 0)
                    {
                        //回调用户中心界面
                        window.location.href = '{:url("User/my_info")}';
                    }
                }
                else
                {
                    alert('服务器错误');
                }
            },'json');

            return false;
        }

    });
</script>
